export default {
    install(Vue) {

        // 浅复制
        Vue.prototype.simpleClone = function (bean) {
            return JSON.parse(JSON.stringify(bean));
        };
        // 保存Token
        Vue.prototype.saveToken = function (token) {
            this.$store.commit('setToken', token);
        };
        // 保存用户信息
        Vue.prototype.saveUser = function (user) {
            this.$store.commit('setUser', user);
        };
        Vue.prototype.saveModuleName = function (playLoad) {
            this.$store.commit('setModuleName', playLoad);
        };
        Vue.prototype.saveMenuName = function (playLoad) {
            this.$store.commit('setMenuName', playLoad);
        };
        Vue.prototype.saveCostShowPrice = function (playLoad) {
            this.$store.commit('setCostShowPrice', playLoad);
        };
        /**
         * 根据ref检查参数
         * @param str
         * @param errorMsg
         * @returns {boolean}
         */
        Vue.prototype.validateRefs = function (refs) {
            for (let i = 0; i < refs.length; i++) {
                var ref = refs[i];
                if (ref == null) {
                    return false;
                }
                if (ref.errorCheck()) {
                    this.scrollIntoView(ref);
                    return true;
                }
            }
            return false;
        };

        /**
         * 根据ref检查参数
         * @param str
         * @param errorMsg
         * @returns {boolean}
         */
        Vue.prototype.validateRef = function (ref) {
            if (ref.errorCheck()) {
                if (ref == null) {
                    return false;
                }
                this.scrollIntoView(ref);
                return true;
            }
            return false;
        };

        /**
         * 清空表单错误信息
         * @param refs
         */
        Vue.prototype.clearValidates = function (refs) {
            for (let i = 0; i < refs.length; i++) {
                const ref = refs[i];
                if (ref != null) {
                    try {
                        ref.clearError();
                    } catch (e) {

                    }
                }
            }
        };

    }
};
